@extends('layouts.app')

@section('content')
    <div class="main-content">
        <div class="search_inp">
                <table width="100%" border="1" class="table_search">
                    <thead>
                        <tr>
                            <th colspan="6">
                                <span>查询条件</span>
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                         
                            <td width="13.33%" align="right"><label>姓名：</label></td>
                            <td width="20%"><input type="text" class="w150" name="name" placeholder="请输入姓名"/></td>
                            <td width="13.33%" align="right"><label>所在单位：</label></td>
                            <td width="20%">
                                <select name="unit_id" class="w150">
                                    <option value="">请选择所属组织</option>
                                    @foreach($units as $k=>$v)
                                        <option value="{{$v->id}}" @if($_POST && $_POST['unit_id'] == $v->id) selected @endif>{{$v->name}}</option>
                                    @endforeach
                                </select>
                            </td>
                            <td width="13.33%" align="right"></td>
                            <td width="20%">
                            
                               <a href="javascript:" class="easyui-linkbutton" data-options="iconCls:'icon-search'" style="width:80px" onclick="doSearch()">查询</a>
                            </td>
                        </tr>

                    </tbody>
                </table>
            </div>

            <script type="text/javascript">
                function doSearch(){
                        $('#dg4').datagrid('load',{
                            unit_id:$("select[name='unit_id']").val(),
                            name: $("input[name='name']").val(),
                        });
                    }

            </script>


            <div class="form-all mg_t30">
                    <div id="tb3" style="padding:3px">
                        <a href="javascript:void(0)" class="easyui-linkbutton"  onclick="edit()" plain="true" iconCls='icon-edit'>查看</a>
                        
                    </div>
                    <table id="dg4" title="单位分色展示" class="easyui-datagrid" style="width:100%;height:650px" toolbar="#tb3"
                            data-options="rownumbers:true,singleSelect:true,pagination:true,pageSize:20,url:'{{url('admin/yanpan/zdry_jiankong')}}',method:'get',toolbar:'#dg4'">
                        <thead>
                            <tr>
                                <th data-options="field:'name'" width="20%" align="center">姓名</th>
                                 <th data-options="field:'uname'" width="20%" align="center">所属单位</th>
                                <th data-options="field:'bianhao'" width="20%" align="center">编号</th>
                                <th data-options="field:'sex'" width="20%" align="center">性别</th>

                                <th data-options="field:'updated_at'" width="20%"  align="center">修改时间</th>
                                <th data-options="field:'user_id'" width="22%" align="center">操作人</th>
                                
                            </tr>
                        </thead>
                    </table>
               </div>
    </div> 
            <script type="text/javascript">
                function edit(){
            //       var row = $('#dg1').datagrid('getSelected');
                    var parent = $(this).parent().next(".datagrid-view").children("table").attr("id");
                    var index =  $('#'+parent).datagrid('getRowIndex', $('#'+parent).datagrid('getSelected'));
                     if(index <0){
                        alert("提示, 请选中要编辑的行！")
                     }else{
                         console.log(index);
                     }
                     
                }
            </script>



        <!-- 考核新增弹框 -->
        <div id="adbg" class="easyui-window" title="添加" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:900px;height: auto;max-height:600px;padding:10px;">
       
        </div>


        <div id="dlg" class="easyui-dialog" title="删除" closed="true" style="width:400px;height:200px;line-height:100px;text-align:center;font-size:16px;padding:10px">
            您确定要删除该列表？
        </div>


        <script type="text/javascript">

            function add(){
                $('#adbg').window({
                title: "新增",
                href: "add_color",
                width:'900',
                height:'600',
                minimizable:false,
                top:($(window).height() - 600) * 0.5,
				left:($(window).width() - 900) * 0.5,
                modal:true,
                closed: false,
                });
            }

            function edit(){
            var row = $('#dg4').datagrid('getSelected');
            if (row) {
                var url = 'view_zdry/'+row.id;
                $('#adbg').window({
                    title: "查看",
                    href: url,
                    width:'900',
                    height:'600',
                    minimizable:false,
	                top:($(window).height() - 600) * 0.5,
					left:($(window).width() - 900) * 0.5,
                    modal:true,
                    closed: false,
                });
            }else {
                $.messager.alert('提示','请选中要查看的行！');
            }
          }


           function setcolor(){
            var row = $('#dg4').datagrid('getSelected');
            if (row) {
                var url = 'save_color/'+row.id;
                $('#adbg').window({
                    title: "编辑",
                    href: url,
                    width:'900',
                    height:'600',
                    minimizable:false,
	                top:($(window).height() - 600) * 0.5,
					left:($(window).width() - 900) * 0.5,
                    modal:true,
                    closed: false,
                });
            }else {
                $.messager.alert('提示','请选中要编辑的行！');
            }
          }

          


          function cancel(){
            var row = $('#dg4').datagrid('getSelected');
            if (row) {
                $('#dlg').dialog({
                    title: "注销",
                    closed: false,
                    modal:true,
                    buttons: [{
                        text: '确定',
                        iconCls: 'icon-ok',
                        handler: zhuxiao
                    }, {
                        text: '取消',
                        iconCls: 'icon-cancel',
                        handler: function () {
                            $('#dlg').dialog('close');
                        }
                    }]
                });
            } else {
                $.messager.alert('提示','请选中要编辑的行！');
            }
        }

        function zhuxiao(){
            $('#dlg').dialog('close');
            var row = $('#dg4').datagrid('getSelected');
            var url = 'del_color/'+row.id;
            $.ajax({
                type: 'get',
                url: url,
                success: function(data){
                    if(data.status == 1){
                        $.messager.alert('信息提示',data.msg,'info');
                      
                        var rowIndex = $('#dg4').datagrid('getRowIndex', row);
                        $('#dg4').datagrid('deleteRow', rowIndex);
                    }else{
                        $.messager.alert('信息提示',data.msg,'info');
                    }
                }
            });
        }


        $("#dg4").datagrid({
            onDblClickRow: function (index, row) {
                edit();
            }
        });


        </script>


     
@stop



